
package ch.hearc.coursJava.moo.chrono;

import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ChronoTest
	{

	/*------------------------------------------------------------------*\
	 |*							Constructeurs							*|
	 \*------------------------------------------------------------------*/

	@Before
	public void before()
		{
		// rien
		}

	@After
	public void after()
		{
		// rien
		}

	/*------------------------------------------------------------------*\
	 |*							Methodes Public							*|
	 \*-----------------------------------------------------------------*/

	@Test
	public void testChrono() throws InterruptedException
		{
		long tolerance = 5;
		Chrono chrono = new Chrono();
		long time0 = chrono.getTime();
		assertTrue(isEgal(time0, 0, tolerance));

		System.out.println(chrono);
		chrono.start();
		Thread.sleep(500);
		long time1 = chrono.getTime();
		assertTrue(isEgal(time1, 500, tolerance));
		System.out.println(chrono);

		Thread.sleep(500);
		chrono.pause();
		long time2 = chrono.getTime();
		assertTrue(isEgal(time2, 1000, tolerance));
		System.out.println(chrono);

		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private boolean isEgal(long time1, long time2, long tolerance)
		{
		return Math.abs(time1 - time2) <= tolerance;
		}

	}
